﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EasyProp.Extensions
{
    public static class TypeExtensions
    {
        public static bool Implements(this Type type, Type typeToImplement)
        {
             return typeToImplement.IsAssignableFrom(type);
        }

        public static void AssertImplements(this Type type, Type typeToImplement)
        {
            string errorMessage = String.Format("{0} must implement {1}.", type, typeToImplement);
            AssertImplements(type, typeToImplement, errorMessage);
        }

        public static void AssertImplements(this Type type, Type typeToImplement, string message)
        {
            if (!type.Implements(typeToImplement))
            {
                throw new ArgumentException(message);
            }
        }


    }
}
